﻿using NLog;
using Stock.Model;
using Stock.Model.DB;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Stock.Dao
{
      public class PublicDao : BaseDao
      {

            /// <summary>
            /// 获取API节假日,保存到表.
            /// 1:工作日,3:双休日,4:节日
            /// </summary>
            /// <param name="holidays"></param>
            public static string InsertDate(Holidays holidays)
            {
                  string sql = string.Empty;
                  sql = string.Format("DELETE FROM T_HOLIDAY WHERE [HOLIDAY_YEAR] = '{0}' AND [HOLIDAY_MONTH] = '{1}';", holidays.year, holidays.month);
                  Delete(sql);
                  foreach (HolidayList holidayList in holidays.holidayLists)
                  {
                        sql = string.Format("INSERT INTO T_HOLIDAY ([HOLIDAY],[STATUS],[HOLIDAY_YEAR],[HOLIDAY_MONTH]) VALUES('{0}','{1}','{2}','{3}');",
                                                holidayList.date, holidayList.status, holidays.year, holidays.month);
                        Insert(sql);
                  }
                  return "";
            }

            /// <summary>
            /// 获取某年的节假日
            /// </summary>
            /// <param name="year"></param>
            /// <returns></returns>
            public static DataTable GetHolidays(string year)
            {
                  string sql = string.Format("SELECT * FROM T_HOLIDAY WHERE [HOLIDAY_YEAR] = '{0}';", year);
                  DataTable dataTable = GetDataTable(sql);
                  return dataTable;
            }

            public static void DelHolidays(int year)
            {
                  string sql = string.Format("DELETE FROM T_HOLIDAY WHERE [HOLIDAY_YEAR] = '{0}';", year);
                  Delete(sql);
            }

            /// <summary>
            /// 获取需要监控的STOCK列表
            /// </summary>
            /// <returns></returns>
            public static DataTable GetStockTable()
            {
                  string sql = "SELECT * FROM [T_STOCK] WHERE [IS_ALERT] = TRUE;";
                  DataTable dataTable = GetDataTable(sql);
                  return dataTable;
            }

      }
}
